<#--<#include "../layout/base.ftl">-->
<#--<#macro header>-->
<style type="text/css">
    #othersearch-panel span.label {
        margin-left: 10px;
    }

    #othersearch-panel .input-text {
        border: 1px solid #6D869E;
        height: 18px;
        vertical-align: middle;
        width: 100px;
    }

    #othersearch-panel span.om-combo, #othersearch-panel span.om-calendar {
        vertical-align: middle;
    }

    .form {
        float: left;
        width: 100%;
        text-align: left;
        border-collapse: collapse;
        background: #fff;
    }

    .form caption {
        font-size: 16px;
        font-weight: bold;
        letter-spacing: 2px;
        color: #19609d
    }

    .form th {
        text-align: right;
        font-size: 14px
    }

    .form tr, .form td {
        padding-left: 3px;
        height: 25px
    }

    .form a:link, .form a:visited {
        color: #246ab5;
        text-decoration: underline
    }

    .form a:hover, .form a:active {
        text-decoration: underline
    }

    .se {
        background: #fafbfe
    }

    .outtable {
        border-collapse: collapse;
    }

    .outtable th {
        border: 1px #d9dde1 solid;
        font-weight: normal;
        color: #173d72;
        text-align: left;
        text-indent: 6px;
        background: #fafbfe;
    }

    .outtable td {
        border: 1px #d9dde1 solid;
        padding: 3px;
        font-size: 14px;
        background: #fff
    }

</style>
<script type="text/javascript">
    $(function () {
        $("#othersearch-panel").omPanel({
            title: "高级搜索"
        });


        $("#otherstatus").omCombo({
            width: 100,
            dataSource: [
                {text: '未导入', value: '1'},
                {text: '已导入', value: '2'}
            ],
            value: '1',
            editable: false
        });

        var start = new Date();
        start.setFullYear(${startTime?string("yyyy")!""}, ${startTime?string("M")!""}-1,${startTime?string("dd")!""});
        var end = new Date();
        end.setFullYear(${endTime?string("yyyy")!""}, ${endTime?string("M")!""}-1,${endTime?string("dd")!""});

        $("#otherstart_time").omCalendar({
            width: 100,
            maxDate: end,
            editable: false,
            onSelect: function (date, event) {
                $("#otherend_time").omCalendar({
                    width: 100,
                    minDate: date,
                    editable: false
                });
            }
        });

        $("#otherend_time").omCalendar({
            width: 100,
            minDate: start,
            editable: false,
            onSelect: function (date, event) {
                $("#otherstart_time").omCalendar({
                    width: 100,
                    maxDate: date,
                    editable: false
                });
            }
        });


        $('span#otherbutton-search').omButton({
            width: 70,
            icons: {left: '${base}/css/default/images/advanced/search.png'},
            onClick: function (event) {
                var url = "${base}/other_voucher/grid_json?status=" + $("#otherstatus").omCombo('value') + "&startTime=" + $("#otherstart_time").val()
                        + "&endTime=" + $("#otherend_time").val() + "&bill=" + $("#otherbill").val()
                        + "&voucher=" + $("#othervoucher").val() + "&operator=" + $("#otheroperator").val();
                $('#othergrid').omGrid("setData", encodeURI(url));
            }
        });

        var url = "${base}/other_voucher/grid_json?status=" + $("#otherstatus").omCombo('value') + "&startTime=" + $("#otherstart_time").val()
                + "&endTime=" + $("#otherend_time").val() + "&bill=" + $("#otherbill").val()
                + "&voucher=" + $("#othervoucher").val() + "&operator=" + $("#otheroperator").val();

        var grid = $('#othergrid').omGrid({
            dataSource: encodeURI(url),
            height: 380,
            width: 'fit',
            autoFit: true,
            limit: 10,
            //单据号码 收款日期 收款类型 客户名称 收款金额 票据号码 入帐银行 类型 审核人 公司名称
            colModel: [
                {header: '公司名称', name: 'company', align: 'left'},
                {header: '制单日期', name: 'time', align: 'left'},
                {header: '单据号', name: 'billNo', align: 'left'},
                {header: '凭证类别', name: 'type', align: 'left'},
                {header: '摘要', name: 'remark', align: 'left'},
                {header: '制单人', name: 'operator', align: 'left'},
                {header: '凭证号', name: 'voucher', align: 'left'},
                {header: '操作', name: 'imported', align: 'center', renderer: function (colValue, rowData, rowIndex) {
                    if (colValue == "0")
                        return '<button onClick="othershowDialog(' + rowData.id + ')">导入</button>';
                    return '';
                }}
            ]
        });

        $(window).scroll(function () {
            $("#othergrid").omGrid('resize');
        });


        $("#otherdialog").omDialog({
            title: "导入凭证",
            autoOpen: false,
            resizable: true,
            modal: true,
            width: 800,
            buttons: [
                {
                    text: "确定",
                    click: function () {
                        $.post('${base}/other_voucher/generate_voucher_json',
                                {'id': $("#other_id").val(), 'attachment': $("#other_attachment").val()},
                                function (data) {
                                    $('span#rp_button_search').omButton("click");
                                    $("#rp_dialog").omDialog("close");
                                    var type = data.responseflag == "1" ? "success" : "error";
                                    $.omMessageBox.alert({
                                        type: type,
                                        title: '提示',
                                        content: data.responsemessage
                                    });
                                }, "json");
                    }
                },
                {
                    text: "取消",
                    click: function () {
                        $("#otherdialog").omDialog("close");
                    }
                }
            ]
        });
    });

    var other_voucher_item_table_row = '<tr><td width="13%" style="padding: 0px">:digest</td>' +
            '<td width="13%" align="left">:subjectname</td>' +
            '<td width="13%" align="right">:debit</td>' +
            '<td width="13%" align="right">:credit</td>' +
            '<td width="13%">:helpname</td></tr>';

    function othershowDialog(id) {
        var data = {"id": id};
        $("#other_id").val(id);
        $.post("${base}/other_voucher/voucher_json", data, function (data, textStatus, jqXHR) {

            $("#othertypecode").html(data.voucher.master.vchrtypecode);
            $("#othercreateuser").html(data.voucher.master.createuser);
            $("#othercreatedate").val(data.voucher.master.systemdate);
            $("#othercreatedate").omCalendar({
                editable: false
            });

            $("#otheritems").html("");
            if (data.voucher.items.length != 0) {
                var items_table = "", sum = 0;
                for (var i = 0; i < data.voucher.items.length; i++) {
                    var item = data.voucher.items[i];
                    var temp = other_voucher_item_table_row.replace(":digest", item.digest);
                    temp = temp.replace(":subjectname", item.subjectname);
                    temp = temp.replace(":debit", item.debit);
                    temp = temp.replace(":credit", item.credit);
                    temp = temp.replace(":helpname", item.helpname);

                    sum += item.debit;

                    items_table += temp;
                }
                $("#otheritems").html(items_table);
            }
            $("#othersum1").html(sum);
            $("#othersum2").html(sum);
            $("#othernote").html(data.voucher.master.note);
            $("#otherbillNo").html(data.voucher.master.billno);
            $("#otherimportType").omCombo({
                width: 138,
                dataSource: [
                    {text: '生成凭证号', value: '1'},
                    {text: '指定凭证号', value: '2'}
                ],
                value: '1',
                editable: false
            });
            $("#other_attachment").val("");
            $("#otherdialog").omDialog('open');
        }, "json");
    }
</script>
<#--</#macro>-->
<#--<#macro body>-->
<div id="othersearch-panel">
    <span class="label">状&nbsp;&nbsp;&nbsp;态：</span>
    <input id="otherstatus"/>
    <span class="label">时&nbsp;&nbsp;&nbsp;间：</span>
    <input id="otherstart_time" style="width: 80px" value="${startTime?string("yyyy-MM-dd")!""}"/>
    <span class="label">&nbsp;&nbsp;&nbsp;&nbsp;至&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
    <input id="otherend_time" style="width: 80px" value="${endTime?string("yyyy-MM-dd")!""}"/>
    <span class="label">单据号：</span>
    <input id="otherbill" type="text" class="input-text"/>
    <br/> <br/>
    <span class="label">凭证号：</span>
    <input id="othervoucher" type="text" class="input-text"/>
    <span class="label">操作人：</span>
    <input id="otheroperator" type="text" class="input-text"/>
    <span id="otherbutton-search">搜索</span>
</div>
<br/>
<table id="othergrid"></table>

<div id="otherdialog">
    <form action='' method='post'>
        <input id="other_id" type="hidden"/>
        <table width="100%">
            <tr>
                <td width="70px">字号</td>
                <td><span id="othertypecode" style="font-size: 12px;font-weight: bold"></span></td>
                <td width="70px">制单人</td>
                <td id="othercreateuser">
                </td>
                <td width="70px">制单日期</td>
                <td>
                    <input id="othercreatedate" type="text" style="width: 120px"/>
                </td>
                <td width="70px">附单据数</td>
                <td>
                    <input id="otherattachment" type="text" style="width: 120px"/>
                </td>
            </tr>
        </table>
        <br/>
        <table width="100%" class="form outtable">
            <thead>
            <tr>
                <th width="28%">摘要</th>
                <th width="28%">科目名称</th>
                <th width="10%">借方金额</th>
                <th width="10%">贷方金额</th>
                <th width="24%">辅助核算</th>
            </tr>
            </thead>
            <tbody id="otheritems">
            </tbody>
            <tr>
                <td height="25px">合计</td>
                <td></td>
                <td align=right style="padding:2px" id="othersum1"></td>
                <td align=right style="padding:2px" id="othersum2"></td>
                <td></td>
            </tr>
        </table>
        <table width="100%">
            <tr>
                <td class="ftitle" width="10%">备注</td>
                <td width="60%" id="othernote"></td>
                <td class="ftitle" width="10%">凭证号</td>
                <td width="20%" id="otherbillNo"></td>
            </tr>
            <tr>
                <td width="70px">导入方式</td>
                <td><input id="otherimportType"/></td>
                <td width="70px">凭证号码</td>
                <td><input id="othervoucherNumber" type="text" style="width: 118px"/></td>
            </tr>
        </table>
    </form>
</div>
<#--</#macro>-->